home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / oxygen.app / Contents / Resources / Java / jh.jar / javax / help / TOCView$TOCParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-06-24  |  5.0 KB  |  213 lines

  1. package javax.help;
  2.  
  3. import com.sun.java.help.impl.LangElement;
  4. import com.sun.java.help.impl.Parser;
  5. import com.sun.java.help.impl.ParserEvent;
  6. import com.sun.java.help.impl.ParserListener;
  7. import com.sun.java.help.impl.Tag;
  8. import com.sun.java.help.impl.TagProperties;
  9. import java.io.IOException;
  10. import java.io.Reader;
  11. import java.util.Hashtable;
  12. import java.util.Locale;
  13. import java.util.Stack;
  14. import javax.swing.tree.DefaultMutableTreeNode;
  15.  
  16. class TOCView$TOCParser implements ParserListener {
  17.    private HelpSet currentParseHS;
  18.    private Stack nodeStack;
  19.    private Stack itemStack;
  20.    private boolean startedtoc;
  21.    private Stack tagStack;
  22.    private Locale defaultLocale;
  23.    private Locale lastLocale;
  24.    private TreeItemFactory factory;
  25.  
  26.    TOCView$TOCParser(TreeItemFactory var1) {
  27.       this.factory = var1;
  28.    }
  29.  
  30.    synchronized DefaultMutableTreeNode parse(Reader var1, HelpSet var2, Locale var3) throws IOException {
  31.       this.nodeStack = new Stack();
  32.       this.tagStack = new Stack();
  33.       this.itemStack = new Stack();
  34.       if (var3 == null) {
  35.          this.defaultLocale = Locale.getDefault();
  36.       } else {
  37.          this.defaultLocale = var3;
  38.       }
  39.  
  40.       this.lastLocale = this.defaultLocale;
  41.       DefaultMutableTreeNode var4 = new DefaultMutableTreeNode();
  42.       this.nodeStack.push(var4);
  43.       this.currentParseHS = var2;
  44.       Parser var5 = new Parser(var1);
  45.       var5.addParserListener(this);
  46.       var5.parse();
  47.       return var4;
  48.    }
  49.  
  50.    public void tagFound(ParserEvent var1) {
  51.       Locale var2 = null;
  52.       Tag var3 = var1.getTag();
  53.       TOCView.access$000("TagFound: " + var3.name);
  54.       TagProperties var4 = var3.atts;
  55.       if (var4 != null) {
  56.          String var5 = var4.getProperty("xml:lang");
  57.          var2 = HelpUtilities.localeFromLang(var5);
  58.       }
  59.  
  60.       if (var2 == null) {
  61.          var2 = this.lastLocale;
  62.       }
  63.  
  64.       if (var3.name.equals("tocitem")) {
  65.          if (!this.startedtoc) {
  66.             this.factory.reportMessage(HelpUtilities.getText("toc.invalidTOCFormat"), false);
  67.          }
  68.  
  69.          if (var3.isEnd && !var3.isEmpty) {
  70.             this.nodeStack.pop();
  71.             this.itemStack.pop();
  72.             this.removeTag(var3);
  73.             return;
  74.          }
  75.  
  76.          TOCItem var10;
  77.          try {
  78.             Hashtable var6 = null;
  79.             if (var4 != null) {
  80.                var6 = var4.getHashtable();
  81.             }
  82.  
  83.             var10 = (TOCItem)this.factory.createItem("tocitem", var6, this.currentParseHS, var2);
  84.          } catch (Exception var9) {
  85.             if (TOCView.access$100()) {
  86.                String var7 = null;
  87.                Object var8 = null;
  88.                if (var4 != null) {
  89.                   var7 = var4.getProperty("target");
  90.                   String var14 = var4.getProperty("image");
  91.                }
  92.  
  93.                System.err.println("Failure in IndexItem Creation; ");
  94.                System.err.println("  id: " + var7);
  95.                System.err.println("  hs: " + this.currentParseHS);
  96.             }
  97.  
  98.             var10 = (TOCItem)this.factory.createItem();
  99.          }
  100.  
  101.          DefaultMutableTreeNode var12 = new DefaultMutableTreeNode(var10);
  102.          DefaultMutableTreeNode var13 = (DefaultMutableTreeNode)this.nodeStack.peek();
  103.          var13.add(var12);
  104.          if (!var3.isEmpty) {
  105.             this.itemStack.push(var10);
  106.             this.nodeStack.push(var12);
  107.             this.addTag(var3, var2);
  108.          }
  109.       } else if (var3.name.equals("toc")) {
  110.          TOCView.access$000("attr: " + var4);
  111.          if (!var3.isEnd) {
  112.             if (var4 != null) {
  113.                String var11 = var4.getProperty("version");
  114.                if (var11 != null && var11.compareTo("1.0") != 0) {
  115.                   this.factory.reportMessage(HelpUtilities.getText("toc.unknownVersion", var11), false);
  116.                }
  117.             }
  118.  
  119.             if (this.startedtoc) {
  120.                this.factory.reportMessage(HelpUtilities.getText("toc.invalidTOCFormat"), false);
  121.             }
  122.  
  123.             this.startedtoc = true;
  124.             this.addTag(var3, var2);
  125.          } else {
  126.             if (this.startedtoc) {
  127.                this.startedtoc = false;
  128.             }
  129.  
  130.             this.removeTag(var3);
  131.          }
  132.  
  133.          return;
  134.       }
  135.  
  136.    }
  137.  
  138.    public void piFound(ParserEvent var1) {
  139.    }
  140.  
  141.    public void doctypeFound(ParserEvent var1) {
  142.    }
  143.  
  144.    public void textFound(ParserEvent var1) {
  145.       TOCView.access$000("TextFound: " + var1.getText().trim());
  146.       if (!this.tagStack.empty()) {
  147.          LangElement var2 = (LangElement)this.tagStack.peek();
  148.          Tag var3 = var2.getTag();
  149.          if (var3.name.equals("tocitem")) {
  150.             TOCItem var4 = (TOCItem)this.itemStack.peek();
  151.             String var5 = var4.getName();
  152.             if (var5 == null) {
  153.                var4.setName(var1.getText().trim());
  154.             } else {
  155.                var4.setName(var5.concat(var1.getText()).trim());
  156.             }
  157.          }
  158.  
  159.       }
  160.    }
  161.  
  162.    public void commentFound(ParserEvent var1) {
  163.    }
  164.  
  165.    public void errorFound(ParserEvent var1) {
  166.       this.factory.reportMessage(var1.getText(), false);
  167.    }
  168.  
  169.    protected void addTag(Tag var1, Locale var2) {
  170.       LangElement var3 = new LangElement(var1, var2);
  171.       this.tagStack.push(var3);
  172.       if (this.lastLocale == null) {
  173.          this.lastLocale = var2;
  174.       } else if (var2 == null) {
  175.          this.lastLocale = var2;
  176.       } else {
  177.          if (!this.lastLocale.equals(var2)) {
  178.             this.lastLocale = var2;
  179.          }
  180.  
  181.       }
  182.    }
  183.  
  184.    protected void removeTag(Tag var1) {
  185.       String var3 = var1.name;
  186.       Locale var4 = null;
  187.  
  188.       while(!this.tagStack.empty()) {
  189.          LangElement var2 = (LangElement)this.tagStack.pop();
  190.          if (var2.getTag().name.equals(var3)) {
  191.             if (this.tagStack.empty()) {
  192.                var4 = this.defaultLocale;
  193.             } else {
  194.                var2 = (LangElement)this.tagStack.peek();
  195.                var4 = var2.getLocale();
  196.             }
  197.             break;
  198.          }
  199.       }
  200.  
  201.       if (this.lastLocale == null) {
  202.          this.lastLocale = var4;
  203.       } else if (var4 == null) {
  204.          this.lastLocale = var4;
  205.       } else {
  206.          if (!this.lastLocale.equals(var4)) {
  207.             this.lastLocale = var4;
  208.          }
  209.  
  210.       }
  211.    }
  212. }
  213.